/*
package demo2;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingDeque;

//模拟实现线程池
class MyThreadPool{
    //首先有一个任务队列
    private BlockingDeque<Runnable> queue=new ArrayBlockingQueue<>(1000);

    //submit方法,把任务添加到队列中
    public void submit(Runnable runnable) throws InterruptedException {
        queue.put(runnable);
    }

    //构造方法，创建出n个线程，执行队列中的任务
    public MyThreadPool(int n){
        for (int i = 0; i < n; i++) {
            Thread t=new Thread(()->{
                Runnable runnable= null;
                try {
                    runnable = queue.take();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                runnable.run();
            });
            t.start();
        }
    }
}

public class test {
    public static void main(String[] args) {
MyThreadPool threadPool=new MyThreadPool(4);
        for (int i = 0; i <4; i++) {
            int id=i;
            try {
                threadPool.submit(new Runnable() {
                    @Override
                    public void run() {
                        System.out.println("hello"+id);
                    }
                });
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
*/
